<template>
	<view class="wrap">
		<!-- <g-btn @click="openPDF" title="打开pdf"></g-btn>
		<button>分享pdf</button>
		<view>缓存:{{cacheSize}} </view>
		<button @click="calculateCacheSize">计算缓存</button>
		<button @click="clearCache">清除缓存</button> -->
        <g-btn @click="toWhatsApp" title="跳转WhatsApp"></g-btn>
	</view>
</template>

<script>
export default {
	data () {
		return {
			cacheSize: '0B'
		}
	},
	onLoad(options) {
		this.calculateCacheSize()
	},
	onShow() {
		
	},
	methods: {
        toWhatsApp() {
            plus.runtime.launchApplication({action: 'https://wa.me/60124001668'}, function(e){
                console.log(e);
            })
        },
		openPDF() {
			uni.downloadFile({
			  url: 'http://tax-cloud.bidou88.cn/images/20210611/d073a51f15c64403a27b8f887c7d1bbe_C859D4C4CE088C62.pdf',
			  success: function (res) {
			    var filePath = res.tempFilePath;
			    uni.openDocument({
			      filePath: filePath,
			      success: function (res) {
			        console.log('打开文档成功');
			      }
			    });
			  }
			});
		},
		calculateCacheSize() {
			plus.cache.calculate((size) => {
				console.log(size);
				let sizeCache = parseInt(size)
				if(sizeCache == 0) {
					this.cacheSize = '0B'
				} else if(sizeCache < 1024) {
					this.cacheSize = `${sizeCache}B`
				} else if(sizeCache < 1048576) {
					this.cacheSize = `${(sizeCache/1024).toFixed(2)}KB`
				} else if(sizeCache < 1073741824) {
					this.cacheSize = `${(sizeCache/1048576).toFixed(2)}MB`
				} else {
					this.cacheSize = `${sizeCache/1073741824}GB`
				}
			})
		},
		clearCache() {
			uni.showModal({
				title: '提示',
				content: '是否清空缓存？',
				success: res => {
					if(res.confirm) {
						plus.cache.clear(() => {
							uni.showToast({
								title: '缓存已清空'
							})
							this.calculateCacheSize()
						})
					}
				}
			})
		}
	}
}
</script>

<style scoped lang="scss">
.wrap {
    padding-top: 100rpx;
}
</style>